/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.appspot.ittrick.drive.trick.controller;

import com.appspot.ittrick.drive.trick.DriveTrick;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;

/**
 * FXML Controller class
 *
 * @author takahara
 */
public class SystemErrorPopWindowController extends BorderPane implements Initializable {

    private Exception exception;
    
    /**
     * エラートレース
     */
    @FXML
    TextArea errorTrace;

    /**
     * コンストラクタ
     */
    public SystemErrorPopWindowController(Exception exception) {
        this.exception = exception;
        this.init();
    }

    /**
     * コントロール初期化
     */
    private void init() {
        // ---------------------------------------------------
        // FXMLのロードと設定
        // ---------------------------------------------------
        FXMLLoader fxmlLoader = new FXMLLoader(DriveTrick.class.getResource("fxml/system_error_pop_window.fxml"));
        fxmlLoader.setRoot(this);
        // 自分自身をコントロールとして設定
        fxmlLoader.setController(this);

        try {
            fxmlLoader.load();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        exception.printStackTrace(pw);
        String trace = sw.toString();

        errorTrace.setText(trace);
    }
}
